var loadingFn = function () {
    var ary = [
        'bg.webp',
        'bg2.webp',
        'bg3.webp',
        'circle.webp',
        'detail-border.webp',
        'invitation.png',
        'item.png',
        'leaf.webp',
        'letterBot.webp',
        'letterTop.webp',
        'qr-code.png',
        'rope.webp',
        'rotate.webp',
        'teacher.jpg',
        'tip.png',
        'wheel-circle.webp',
        'wheel-star.webp',
        '1.mp3'
        ];
    var $processBar = $(".progress-bar");
    var $loading = $(".loading");
    var num = 0, timer = null;
    $.each(ary, function (index, item) {
        var reg = /\.([a-zA-Z1-9]+)/i;
        var type = reg.exec(item)[1];
        if (type == "mp3") {
            var oAudio = new Audio;
            oAudio.src = 'audio/' + item;
            oAudio.onloadedmetadata = load;
        } else {
            var oImg = new Image();
            oImg.src = "img/" + item;
            oImg.onload = load;
        }
    });
    function load() {
        num++;
        $processBar.css("width", num / ary.length * 100 + "%");
        if (num == ary.length){
            $loading.remove();
            indexFn.init();
        }
    }
}
window.onload = function(){
    loadingFn();
}
var indexFn = (function(){
    function init(){
        musicFn.init()
        var mySwiper = new Swiper("#swiper", {
            direction: "vertical",
            loop: false,
            effect: "slide",
            onTransitionEnd: change,
            onInit: change,
        });
        function change(example){
            var slidesAry = example.slides,
                activeIndex = example.activeIndex;
            $.each(slidesAry,function(index,item){
                if(index === activeIndex){
                    item.id ='slide'+(activeIndex);
                    return;
                }
                item.id =null;
            });
        }
    }
    return {init: init};
})()


var musicFn = (function () {
    var $audio = $(".music")[0];
    var music=$(".audiobox");
    function init(i) {
        $audio.play();
        music.singleTap(choose);
    }
    function choose(){
        if($audio.paused){
            $audio.play();
            music[0].classList.add('rotate');
            //addClass(autiobtn, 'rotate');
            console.log("hello");
        }else{
            $audio.pause();
            //removeClass(autiobtn, 'rotate');
            music[0].classList.remove('rotate');
            console.log("hello2")
        }
    }
    return {init: init}
})();












